<?php
/*
$id = $_GET['index'];                           //getting article id
$cid = $_GET['category'];                       //getting category id
$feed_url = "http://rss.bdnews24.com/rss/getfeed.php?ln=en&cid=" . $cid . "&ct=n";
$content = file_get_contents($feed_url) . "</rss>";
$xml_data = new SimpleXMLElement($content);

//generating the other news of this section
$other_news = '<ul>';

if ($cid == 0) {
    $other_news .='<li>Others Top News</li>';
} else if ($cid == 1) {
    $other_news .='<li>Others World News</li>';
} else if ($cid == 2) {
    $other_news .='<li>Others News of Bangladesh</li>';
} else if ($cid == 3) {
    $other_news .='<li>Others Political News</li>';
} else if ($cid == 4) {
    $other_news .='<li>Others Bussiness News</li>';
} else if ($cid == 5) {
    $other_news .='<li>Others Sports News</li>';
} else if ($cid == 26) {
    $other_news .='<li>Others Cricket News</li>';
}

foreach ($xml_data->content->item as $news) {
    $url = $news->link;
    $article_id = substr($url, 39, 6);          //grabing the article id from url
    if ($article_id === $id) {
        $title = $news->title;                  //grab the title of article
        $body = $news->details;                 //grab the article details
        $feed_details = substr($body, 0, 200);
        $img_src = $news->image;                //grab the image url
    } else {
        $n_title = $news->title;
        $other_news .='<li><a href="readArticle.php?index=' . $article_id . '&category=' . $cid . '" style="color:#2B3856">' . $n_title . '</a></li>';
    }
}
$other_news .='</ul>';


//creating image tag
$image = '<img src="' . $img_src . '" />';


//generating url for comment and feed
$comment_url = "https://apps.facebook.com/bdnews_twenty_four/readArticle.php?index=" . $id . "&category=" . $cid;

//generating url for read action
$readAction_url = "https://apps.bdnews24.com/fb/readArticle.php?index=" . $id . "&category=" . $cid;

//generating url for origin site
$bdnews_url = "http://www.bdnews24.com/details.php?id=" . $id;

//build the comment
$comment = '<div class="fb-comments" data-href=' . $comment_url . ' data-num-posts="2" data-width="470"></div>'; */
?>


<?php
$id = urldecode($_GET['index']);
$category = $_GET['category'];

$other_news = '<ul>';

if ($category == "top_news") {
    $other_news .='<li>Others Top News</li>';
    $feed_url = "http://dev.bdnews24.com/?widgetName=rssfeed&widgetId=1150&getXmlFeed=true";
} else if ($category == "bangladesh") {
    $other_news .='<li>News of Bangladesh</li>';
    $feed_url = "http://dev.bdnews24.com/bangladesh/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true";
} else if ($category == "politics") {
    $other_news .='<li>Others Politics News</li>';
    $feed_url = "http://dev.bdnews24.com/politics/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true";
} else if ($category == "business") {
    $other_news .='<li>Others Business News</li>';
    $feed_url = "http://dev.bdnews24.com/business/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true";
} else if ($category == "sport") {
    $other_news .='<li>Others Sports News</li>';
    $feed_url = "http://dev.bdnews24.com/sport/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true";
} else if ($category == "world") {
    $other_news .='<li>Others World News</li>';
    $feed_url = "http://dev.bdnews24.com/world/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true ";
} else if ($category == "cricket") {
    $other_news .='<li>Others Cricket News</li>';
    $feed_url = "http://dev.bdnews24.com/cricket/?widgetName=rssfeed&widgetId=1210&getXmlFeed=true";
}

$content = file_get_contents($feed_url);
$xml_data = new SimpleXMLElement($content);

foreach ($xml_data->channel->item as $news) {
    $url = $news->link;
    $article_id = substr($url, 23);

    if ($article_id === $id) {
        $title = $news->title;                  //grab the title of article
        $body_encoded = $news->details;                 //grab the article details
        $feed_details = $news->description;     //grab the description of news article
        $img_src = $news->image;                //grab the image url
        $bdnews_url = $url;
        $body = html_entity_decode($body_encoded);      // to decode the html special character.
    } else {
        $n_title = $news->title;
        $other_news .='<li><a href="readArticle.php?index=' . urlencode($article_id) . '&category=' . $category . '" style="color:#2B3856">' . $n_title . '</a></li>';
    }
}

$other_news .='</ul>';


//creating image tag
$image = '<img src="' . $img_src . ' "height="225" width="300" />';


//generating url for comment and feed
$comment_url = "https://apps.facebook.com/bdnews_twenty_four/readArticle.php?index=" . urlencode($id) . "&category=" . $category;

//generating url for read action
$readAction_url = "https://apps.bdnews24.com/fb/readArticle.php?index=" . urlencode($id) . "&category=" . $category;

//generating url for origin site


//build the comment
$comment = '<div class="fb-comments" data-href=' . $comment_url . ' data-num-posts="2" data-width="470"></div>';
?>


<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#" lang="en">
    <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" />

        <title><?php echo $title; ?></title>
        <link rel="stylesheet" href="stylesheets/screen.css" media="Screen" type="text/css" />
        <link rel="stylesheet" href="stylesheets/mobile.css" media="handheld, only screen and (max-width: 480px), only screen and (max-device-width: 480px)" type="text/css" />

        <!--[if IEMobile]>
        <link rel="stylesheet" href="mobile.css" media="screen" type="text/css"  />
        <![endif]-->

        <!-- These are Open Graph tags.  They add meta data to your  -->
        <!-- site that facebook uses when your content is shared     -->
        <!-- over facebook.  You should fill these tags in with      -->
        <!-- your data.  To learn more about Open Graph, visit       -->
        <!-- 'https://developers.facebook.com/docs/opengraph/'       -->

        <meta property="og:title" content="<?php echo $title; ?>" />
        <meta property="og:type" content="article" />
        <meta property="og:url" content="<?php echo $comment_url; ?>" />
        <meta property="og:image" content="<?php echo $img_src; ?>" />
        <meta property="og:site_name" content="<?php echo $title; ?>" />
        <meta property="og:description" content="<?php echo $feed_details; ?>" />
        <meta property="fb:app_id" content="315241705214029" />

        <script type="text/javascript" src="javascript/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="javascript/myScript.js"></script>

    </head>
    <body>

        <div id="fb-root"></div>

        <div id="content">
            <!-- The heading section of the webpage -->
            <div id="pageHeading">
                <div id="heading">
                    <a href="index.php"><img src="images/heading1.gif"/></a>
                </div>

                <div id="join" onclick="requestToFriends();">
                    <a href="#" class="inviteFriend">Invite Your Friends</a>
                </div>

                <div id="e_to_b">
                    <a href="bangla_index.php"><img src="images/bangla.gif"></a>
                </div>
            </div>

            <!-- The main article section of the webpage that should be read by visitors-->
            <div id="articleArea">

                <!-- Title of the article -->
                <?php echo '<h2>' . $title . '</h2>'; ?>

                <!-- Image of the article -->
                <div id="image" align="center">
                    <?php echo $image; ?>
                </div>

                <!-- main body of the article-->
                <div id="articleBody">
                    <?php echo '<br/>' . $body . '<br/><br/>'; ?>
                </div>
                <br/>
                <!-- Display the facebook like button -->
                <div id="likeArea">
                    <div class="fb-like"  data-width="300" ></div>
                </div>
                <br/>
                <!-- Display the comment section at the bottom of the page -->
                <div id="commentArea">
                    <?php echo $comment; ?>
                </div>
            </div>




            <div id="sidebar">

                <!-- This section will send the app request to friends 
                <div id="join" onclick="requestToFriends();">
                    <a href="#" class="inviteFriend">Invite Your Friends</a>
                </div> -->


                <!-- This section will take the visitor to the official fan page -->


                <!-- This section will take to the visitor to the origin site -->
                <a href="<?php echo $bdnews_url; ?>" target="_blank" class="external">Read this article at bdnews24.com</a><br/>


                <!-- This section will fire the postToFeed() fuction which will post on the users wall -->
                <div id="feed" onclick="postToFeed()">
                    <a href="#" class="inviteFriend">Post on Your Timeline</a>
                </div>

                <!-- The section will make this article a trending one -->
                <br/><a href="https://www.facebook.com/settings?tab=applications&app_id=315241705214029" target="_blank"> Your app settings</a><br/>

                <div id="remove" onclick="deleteAction()">

                </div>

                <!-- This section will display others news of this news category -->

                <!-- <h2 class="label3">Other Top News</h2> -->
                <div id="news_others">
                    <?php echo $other_news; ?>
                </div>

            </div>





            <!-- function that will be fired on action of feed -->
            <script type="text/javascript">
                
                var myTitle = "<?php echo $title; ?>";
                var myLink = "<?php echo $comment_url; ?>";
                var myExcerpt = "<?php echo $feed_details; ?>"
                var myPicture = "<?php echo $img_src; ?>";
                
                function postToFeed() {
                    FB.ui({
                        method: 'feed',
                        'link': myLink,
                        'picture': myPicture,
                        'name': myTitle,
                        'caption': 'BdNews24.com',
                        'description': myExcerpt,
                        actions: [
                            { name: 'share', link: myLink }
                        ]
                    }, function(response) {
                        if (response && response.post_id) {
                        } else {
                        } //Response from post attempt
                    }); // Call to FB.ui
                } // postToFeed
                
            </script>



        </div>

        <!-- Function that will be fired during read action -->
        <script type="text/javascript">
            
            var actionId;
            var output;
            
            setTimeout(function(){
                FB.api(
                '/me/news.reads',
                'post',
                { article: '<?php echo $readAction_url; ?>' },
                function(response) {
                    if (!response || response.error) {
                    } else {
                        
                        actionId = response.id;
                        output = '<a href="#">Remove from Timeline</a>';
                        $('div#remove').html(output);
                        
                    }
                });
            }, 11000);
			
            function deleteAction(){
                FB.api(
                '/'+actionId,
                'delete',
                function(response){
                    if(!response || response.error){
                        
                    }else{
                        output = "";
                        $('div#remove').html(output);
                    }
                });
            }
            
        </script>

        <!-- analytic data -->
        <script type="text/javascript">

            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-4785525-1']);
            _gaq.push(['_setDomainName', '.bdnews24.com']);
            _gaq.push(['_trackPageview']);
			
            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
			
        </script>

    </body>
</html>